<?php


namespace App\Http\Controllers\Common;
use App\Exceptions\ValidatorException;
use App\Http\Controllers\Controller;
use App\Http\Repositories\Repository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class IndexController extends Controller
{
    private $repository;


    public $p = 1;
    public function index(Request $request)
    {

        foreach (false as $item) {
            dd($item);
        }
        dump($this->p);
        $this->p = 2;
        (new MailController)->index();
       return strtotime(date('Y-m-d', strtotime('+1 day')));
    }

    public function sendMail(Request $request)
    {
//        return view('email');
        //验证规则
        $rules = [
            'email' => 'required|array',
            'content' => 'array'
        ];
        //验证错误信息自定义
        $messages = [

        ];
        //验证结果 错误就抛出异常
        $validator = Validator::make($request->all(), $rules, $messages);
        if ($validator->fails()) {
            throw new ValidatorException($validator->errors()->all());
        }

        return $this->repository->sendMail($validator->getData());
    }
}
